<template>
    <div class="product_list">
        <div class="page_img"></div>
        <div class="header">
            <van-nav-bar :title="type" left-text="" left-arrow @click-left="handleBack" />
        </div>
        <div class="product_list_serch_text">
            <van-search class="product_list_serch1" v-model="searchValue" shape="round" background="#F6FAFF"
                placeholder="请输入供应商名称" >
                <template #left-icon>
                    <div class="search_l_bt"></div>
                </template>
                <template #right-icon>
                    <div class="search_r_bt" @click="onSearch">搜索</div>
                </template>
            </van-search>
           
        </div>
        <van-pull-refresh v-model="refreshing" class="pull_box" @refresh="onRefresh">
            <van-list v-model:loading="loading" :finished="finished" @load="onLoad">
                <template v-slot:finished>
                    <div class="nothing_div" v-if="list.length == 0">
                        <van-image :src="nothingData"></van-image>
                        <div class="nothing_font">暂无数据</div>
                    </div>
                </template>
                <div class="product_list_van_list">
                    <div v-for="(item, index) in list" :key="index">

                        <div  class="product_list_van_list_div"
                            @click="handleGetDetails(item.id)">
                            <div class="div_right">
                                <div class="div_right_top">
                                    <div class="style_name">
                                        {{ item.supplierName }}
                                    </div>
                                </div>
    
                                <div class="div_right_bottom">
                                    <div class="div_right_bottom_div">
                                        <div class="value">{{ item.productsCount }}</div>
                                        <div class="label">商品总数</div>
                                    </div>
                                    <div class="b_line"> </div>
                                    <div class="div_right_bottom_div">
                                        <div class="value">{{ item.productsShopping }}</div>
                                        <div class="label">上架总数</div>
                                    </div>
                                    <div class="b_line"> </div>
                                    <div class="div_right_bottom_div">
                                        <div class="value">{{ item.productsOpt }}</div>
                                        <div class="label">选品数</div>
                                    </div>
                                </div>
    
                                <div class="div_right_center">
                                    <div class="contract">
                                        <div :style="{
                                            color: item.sellStatus == '1' ? '#19D11B' : '#FC2540',
                                            backgroundColor: item.sellStatus == '1' ? '#E7FDEE' : '#FDE7E7',
                                        }">
                                            供销合同
                                            <van-image class="van-image"
                                            :src="item.sellStatus == '1' ? icon_duihaolvse : icon_wenhaohongse"></van-image>
                                        </div>
                                    </div>
                                    <div class="contract_break">
                                        <div :style="{
                                            color: item.discountStatus == '1' ? '#19D11B' : '#FC2540',
                                            backgroundColor: item.discountStatus == '1' ? '#E7FDEE' : '#FDE7E7',
                                        }">
                                            破价合同
                                            <van-image class="van-image"
                                            :src="item.discountStatus == '1' ? icon_duihaolvse : icon_wenhaohongse"></van-image>
                                        </div>
                                    </div>
                                    <div class="contract_break">
                                        <div :style="{
                                            color: item.depositStatus == '1' ? '#19D11B' : '#FC2540',
                                            backgroundColor: item.depositStatus == '1' ? '#E7FDEE' : '#FDE7E7',
                                        }">
                                            保证金协议
                                            <van-image class="van-image"
                                            :src="item.depositStatus == '1' ? icon_duihaolvse : icon_wenhaohongse"></van-image>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="line"></div>
                    </div>
                </div>
            </van-list>
        </van-pull-refresh>
    </div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { selectJLMerchantStatistics, selectSignContractStatistics } from "@/api/productList/index";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
    supplierName: "",
    sellStatus: "",
});
const refreshing = ref(false);
const loading = ref(false);
const finished = ref(false);
const list = ref<any[]>([]);
const route = useRoute();
const nothingData = new URL("@/assets/porduct/icon_zanwushuju.png", import.meta.url).href
const icon_duihaolvse = new URL("@/assets/productHome/icon_duihaolvse1.png", import.meta.url).href;
const icon_wenhaohongse = new URL("@/assets/newui/productList/icon_hongsecha@2x.png", import.meta.url).href;
const searchValue = ref("");

/** 商品类型 */
const type: any = computed(() => {
    return route.query.type;
});
/** 开始时间 */
const startTime = computed(() => {
    return route.query.startTime;
});
/** 结束时间 */
const endTime = computed(() => {
    return route.query.endTime;
});
/** 筛选周期类型 */
const avtiveIndex = computed(() => {
    return route.query.avtiveIndex;
});
// 限制连续刷新数据重复问题
const refreFlag = ref(true)
/** 返回 */
const handleBack = () => {
    router.push({
        path: '/home/index',
        query: {
            idnexs: avtiveIndex.value,
            startTime: startTime.value,
            endTime: endTime.value
        }
    })
}
/** 获取详情 */
const handleGetDetails = (id: string) => {
    router.push(`/supplierDetail/${id}`);
};
/** 查询商品列表 */
const getList = async () => {
    if (type.value == '建联商家') {
        var res = await selectJLMerchantStatistics(Object.assign(queryParams.value, {
            startTime: startTime.value,
            endTime: endTime.value
        }));
    } else if (type.value == '签署合同') {
        var res = await selectSignContractStatistics(Object.assign(queryParams.value, {
            startTime: startTime.value,
            endTime: endTime.value
        }));
    }
    refreFlag.value = true
    // 空数据 停止加载
    if (res.rows.length == 0) {
        list.value = [];
        finished.value = true;
        return;
    }
    // 有数据 赋值列表 加载状态结束
    res.rows.forEach((item) => {
        finished.value = false;
        list.value.push(item);
    });
    loading.value = false;
    refreshing.value = false;
    // 如果list长度大于等于总数据条数，数据全部加载完成
    if (list.value.length >= res.total) {
        finished.value = true; //结束加载
    }
};
/** 加载更多 */
const onLoad = async () => {
    getList();
    queryParams.value.pageNum++;
};
/** 下拉 */
const onRefresh = () => {
    if (refreFlag.value) {
        refreFlag.value = false
        finished.value = false; // 清空列表数据
        refreshing.value = false;
        loading.value = true; // 加载状态
        queryParams.value.pageNum = 1; // 分页数赋值为1
        list.value = []; // 清空数组
        onLoad(); // 重新加载数据
    } else {
        finished.value = false;
        refreshing.value = false;
    }
};
/** 搜索 */
const onSearch = () => {
    queryParams.value.supplierName = searchValue.value;
    onRefresh();
};
onMounted(() => { });
</script>
<style lang="less" scoped>
.product_list {
    width: 100%;
    height: 100vh;
    background-color: #fff;
    background: url("@/assets/newui/productList/icon_shangpinbeijing@2x.png");
    background-size: 100%;
    background-repeat: no-repeat;
    position: relative;

    .page_img {
        background: url("@/assets/newui/productList/supplierList@2x.png");
        background-size: 100% 100%;
        position: absolute;
        width: 60px;
        height: 60px;
        top: 52px;
        right: 63px;
    }
    .header {
        filter: blur(0px);
        height: 90px;
        padding-top: 44px;
        box-sizing: border-box;
        width: 100%;
        position: relative;
        z-index: 6003;

        :deep(.van-icon-arrow-left) {
            color: #1a1b1c !important;
           
        }

        :deep(.van-nav-bar) {
            background: none !important;
            &::after{
                border:none;
            }
        }

        :deep(.van-nav-bar__content) {
            background-color: transparent !important;
        }
    }

    .product_list_serch_text {
        display: flex;
        align-items: center;
        width: 100%;
        height: 50px;
        position: relative;
        box-sizing: border-box;
        padding: 0 15px;

        :deep(.van-search__field) {
            background-color: #fff;
            border-radius: 20px;
        }

        .product_list_serch1 {
            display: flex;
            align-items: center;
            width: 100%;
            height: 34px;
            padding: 0px;
            box-sizing: border-box;
            overflow: hidden;
            background-color: #fff;
            border: 1px solid #0094ff;
            border-radius: 20px;

            :deep(.van-search__content) {
                height: 35px;
                background-color: #fff;
            }

            :deep(.van-search__field) {
                height: 35px;
            }

            .search_l_bt {
                width: 14px;
                height: 14px;
                background-image: url("@/assets/newui/productList/icon_sousuo@2x.png");
                background-size: 100% 100%;
            }

            .search_r_bt {
                width: 54px;
                height: 26px;
                background: linear-gradient(146deg, #0064ff 0%, #008fff 100%);
                border-radius: 14px;
                font-weight: 500;
                font-size: 14px;
                color: #ffffff;
                line-height: 26px;
                text-align: center;
                transform: translateX(5px);
            }
        }

        
    }

    .nothing_div {
        width: 100%;
        margin: auto;
        text-align: center;
        margin-top: 20vh;
        font-weight: 400;
        font-size: 12px;
        color: #B8BECA;
        line-height: 12px;
        flex-wrap: wrap;

        .van-image {
            width: 160px;
            height: 160px;
        }

    }

    .product_list_serch-text {
        display: flex;
        align-items: center;
        width: 100%;
        background: #f6faff;
        height: 50px;
        position: relative;

        :deep(.van-search__field) {
            background-color: #fff;
            border-radius: 20px;
            padding-left: 15px;
        }

        .product_list_serch1 {
            display: flex;
            align-items: center;
            background: #f6faff;
            width: 100%;
            height: 35px;

            :deep(.van-search__content) {
                height: 35px;
            }

            :deep(.van-search__field) {
                height: 35px;
            }
        }

        
    }

    &_serch {
        display: flex;
        width: calc(100% - 20px);
        align-items: center;
        justify-content: space-between;
        padding: 0 10px;
        height: 40px;
        background-color: #fff;
        margin-bottom: 10px;

        &_div {
            width: 100%;
            height: 40px;
            overflow: hidden;

            &_line {
                height: 40px;
                display: flex;
                width: 760px;
            }
        }

        :deep(.van-image) {
            width: 20px;
            height: 20px;
        }

        &_item {
            color: #1a1b1c;
            text-align: center;
            font-size: 12px;
            line-height: 40px;
            padding: 0 5px;
        }

        &_active {
            color: #0094ff;
            border-bottom: 3px solid #0094ff;
        }
    }

    :deep(.van-pull-refresh) {
        height: calc(100vh - 140px);
        overflow: scroll;
    }

    .product_list_van_list {
        // min-height: calc(100vh - 140px);
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;

        .line {
            height: 8px;
            background: #F6FAFF;
        }

        .product_list_van_list_div {
            width: 100%;
            box-sizing: border-box;
            background-color: #fff;
            padding: 15px;
            display: flex;
            justify-content: space-between;
        }

        .div_right {
            width: 100%;
            display: flex;
            flex-wrap: wrap;

            .div_right_top {
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: space-between;

                .style_name {
                    font-weight: 500;
                    font-size: 16px;
                    color: #1A1B1C;
                    line-height: 16px;
                }

                .stats {
                    text-align: center;
                    border-radius: 3px;
                    height: 22px;
                    background: #EBF4FF;
                    border-radius: 2px;
                    line-height: 22px;
                    font-weight: 500;
                    font-size: 12px;
                    color: #0094FF;
                    min-width: 70px;
                }
            }

            .div_right_center {
                width: 100%;
                color: #a3a3a3;
                margin-top: 10px;
                font-size: 12px;
                display: flex;
                align-items: center;

                .contract {
                    div {
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        width: 105px;
                        height: 22px;
                        border-radius: 5px;

                        .van-image {
                            width: 12px;
                            height: 12px;
                            margin-left: 5px;
                        }
                    }
                }

                .contract_break {
                    margin-left: 15px;

                    div {
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        width: 105px;
                        height: 22px;
                        border-radius: 5px;

                        .van-image {
                            width: 12px;
                            height: 12px;
                            margin-left: 5px;
                        }
                    }
                }
            }

            .div_right_bottom {
                display: flex;
                width: 100%;
                align-items: center;
                justify-content: space-between;
                margin-top: 7px;
                background: #F7F7F799;
                border-radius: 5px;
                box-sizing: border-box;
                padding: 10px 0;

                .b_line {
                    width: 1px;
                    height: 19px;
                    background-color: #ECECF2;
                }

                .div_right_bottom_div {
                    width: 0;
                    flex: 1;
                    display: flex;
                    flex-direction: column;
                    align-items: center;

                    .label {
                        font-weight: 400;
                        font-size: 12px;
                        color: #8492AD;
                        line-height: 12px;
                        text-align: left;
                        font-style: normal;
                        text-transform: lowercase;
                        margin-top: 5px;
                    }

                    .value {
                        font-weight: 500;
                        font-size: 12px;
                        color: #1A1B1C;
                        line-height: 12px;
                        text-align: left;
                        font-style: normal;
                    }
                }
            }
        }
    }
}
.pull_box{
    background: #FFFFFF;
    border-radius: 15px 15px 0px 0px;
    
}
</style>